package pratise;

public class Merge {
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int index1 = m - 1;
        int index2 = n - 1;
        int last = m + n - 1;
        while (index2 >= 0 && index1 >= 0) {
            if(nums2[index2] > nums1[index1]) {
                nums1[last--] = nums2[index2--];
            } else {
                nums1[last--] = nums1[index1--];
            }
        }
        if(index2 >= 0) {
            for (int i = 0; i <= index2; i++) {
                nums1[i] = nums2[i];
            }
        }
    }

    public static void main(String[] args) {
        int[] arr1 = {1,2,3,0,0,0};
        int m = 3;
        int[] arr2 = {2,5,6};
        int n = 3;
        merge(arr1, m, arr2, n);

    }
}
